home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / wdj0696.zip / NELSON.ZIP / BUG0696.CPP
C/C++ Source or Header  |  1996-03-26  |  956b  |  41 lines

  1. //
  2. // BUG0696.CPP
  3. //
  4. // The following bug illuminates a problem in the
  5. // Borland C++ 4.5 16 bit code generator.  If you select
  6. // just the -Oc option, which performs local duplicate
  7. // expression optimization, the routine will fail
  8. // to correctly update buffer[ index ].  Viewing the
  9. // generated assembly code shows that the value is
  10. // in fact not modified at all!
  11. //
  12. // Build with: bcc -Oc bug0696.cpp
  13. //
  14. #include <iostream.h>
  15.  
  16. int buffer[ 1 ] = { -1 };
  17. unsigned char index = 0;
  18.  
  19. int set_element( int flag )
  20. {
  21.     int dummy = buffer[ index ];
  22.     buffer[ index ] = ( flag > 0 );
  23.     return dummy;
  24. }
  25.  
  26. int main()
  27. {
  28.     set_element( 1 );
  29.     cout << "\nbuffer[ 0 ] = "
  30.          << buffer[ 0 ]
  31.          << "\n";
  32.     cout << "\nNote that the value should be "
  33.             "either 0 or 1!\n\n";
  34.     if ( buffer[ 0 ] != 1 )
  35.         cout << "Bug!\n";
  36.     else
  37.         cout << "No bug!\n";
  38.     return 1;
  39. }
  40. //End of file
  41.